package org.jeecg.common.util.mail;

import org.jeecg.common.util.SpringContextUtils;
import org.jeecg.config.StaticConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 邮件发送工具类
 *
 * @author xc
 */
public class MailSender extends Thread {

    private static final Logger logger = LoggerFactory.getLogger(MailSender.class);

    String subject;
    String to;
    String neirong;
    String file;

    public MailSender(String subject, String to, String neirong) {
        this.to = to;
        this.subject = subject;
        this.neirong = neirong;
    }

    public MailSender(String subject, String to, String neirong, String file) {
        this.to = to;
        this.subject = subject;
        this.neirong = neirong;
        this.file = file;
    }

    public void start() {
        // 从配置信息中取邮箱配置地址
        StaticConfig staticConfig = SpringContextUtils.getBean(StaticConfig.class);
        String smtp = staticConfig.getEmailHost(); // smtp服务器地址
        String pop = staticConfig.getEmailPop(); // "pop服务器地址"
        String from = staticConfig.getEmailFrom(); // ("邮箱发件地址");
        String username = staticConfig.getEmailUsername(); // ("邮箱用户名");
        String password = staticConfig.getEmailPwd(); // ("邮箱密码");
        MailUtil mailUtil = new MailUtil(smtp, pop, from, username, password);
        mailUtil.sendmail(this.subject, this.to, this.neirong, this.file);
    }

    public static void main(String[] a) {
        (new MailSender("审核通知", "346588750@qq.com,", "neirong")).start();
    }

    public static void send(String subject, String to, String context) {
        (new MailSender(subject, to, context)).start();
    }

    public static void send(String subject, String to, String context, String file) {
        (new MailSender(subject, to, context, file)).start();
    }

}
